package com.ehotting.edsta.diagnosisPredict.feign;

import com.ehotting.eaf.core.web.domain.diagnosisPredict.PageDto;
import com.ehotting.eaf.core.web.domain.diagnosisPredict.Response;
import com.ehotting.edsta.diagnosisPredict.domain.dto.ConnectInfoDto;
import com.ehotting.edsta.diagnosisPredict.domain.dto.SQLRequestDto;
import com.ehotting.edsta.diagnosisPredict.feign.factory.DatabaseInfoFallbackFactory;
import com.ehotting.edsta.diagnosisPredict.feign.factory.MaterialFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 建模数据管理模块feignClient
 */
@FeignClient(name = "DatabaseInfo", url = "${request.url.prefix}/databaseinfo", fallbackFactory = DatabaseInfoFallbackFactory.class)
public interface DatabaseInfoFeignService {

    /**
     * 新增数据库连接信息
     * @param dto
     * @return
     */
    @PostMapping(value = "/insert-database")
    Response<String> insertDatabase(@RequestBody ConnectInfoDto dto);

    /**
     * 更新连接账号密码
     * @param id
     * @param password
     * @param user
     * @return
     */
    @GetMapping(value = "/update-database")
    Response<String> updateDatabase(@RequestParam("id") Long id,
                                    @RequestParam("password") String password,
                                    @RequestParam("user") String user);

    /**
     * 查询历史数据库连接信息
     * @param creater
     * @return
     */
    @GetMapping(value = "/history")
    Response<List<ConnectInfoDto>> history(@RequestParam("creater") String creater);

    /**
     * 获取连接素材库所有素材表
     * @param id
     * @param likeStr
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/get-table-list/{id}")
    Response<PageDto<String>> getTableList(@PathVariable("id") Long id,
                                           @RequestParam("likeStr") String likeStr,
                                           @RequestParam("page") Integer page,
                                           @RequestParam("pageSize") Integer pageSize);

    /**
     * 根据表格获取预览前10行数据
     * @param id
     * @param tableName
     * @return
     */
    @GetMapping(value = "/get-by-table")
    Response<Map<String,Object>> getByTable(@RequestParam("id") Long id, @RequestParam("tableName") String tableName);

    /**
     * 根据sql获取预览前10行数据
     * @param requestDto
     * @return
     */
    @PostMapping(value = "/get-by-sql")
    Response<Map<String,Object>> getBySql(@RequestBody SQLRequestDto requestDto);

}